package com.qkjia.day02;

import java.util.concurrent.*;

public class Test07_BlockingQueue {
    public static void main(String[] args) throws InterruptedException {
       BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(2);
       new LinkedBlockingQueue();
       new SynchronousQueue();
        //第一组 抛出异常  粗暴
//        System.out.println(blockingQueue.add("a"));
//        System.out.println(blockingQueue.add("b"));
        //如果队列满了抛异常
//        System.out.println(blockingQueue.add("c"));

//        System.out.println(blockingQueue.remove());
//        System.out.println(blockingQueue.remove());
        //如果队列空抛异常
//        System.out.println(blockingQueue.remove());

        //第二组 温柔 满了返回false 空了返回null
//        System.out.println(blockingQueue.offer("a"));
//        System.out.println(blockingQueue.offer("b"));
//        System.out.println(blockingQueue.offer("c"));
//
//        System.out.println(blockingQueue.poll());
//        System.out.println(blockingQueue.poll());
//        System.out.println(blockingQueue.poll());
        //第三组 有一种很堵的感觉  名副其实阻塞
//        blockingQueue.put("a");
//        blockingQueue.put("b");
//        blockingQueue.put("c");
//
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());
//        System.out.println(blockingQueue.take());


        //第四组 过时不候
        System.out.println(blockingQueue.offer("a"));
        System.out.println(blockingQueue.offer("b"));
        System.out.println(blockingQueue.offer("c",3, TimeUnit.SECONDS));

        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll(3,TimeUnit.SECONDS));

    }
}
